<?php

declare(strict_types=1);

namespace App\Model;



/**
 * @property int $id ID
 * @property string $msg_id 消息ID
 * @property string $group_id 会话ID
 * @property int $userid 发送者ID
 * @property string $user_nick 
 * @property int $user_type 角色
 * @property int $user_level 等级
 * @property int $msg_type 消息类型
 * @property string $msg_data 消息内容
 * @property int $send_time 发送时间
 * @property-read null|User $user 
 */
class ImGroupMessage extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'im_group_message';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'msg_id', 'group_id', 'userid', 'user_nick', 'user_type', 'user_level', 'msg_type', 'msg_data', 'send_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'user_type' => 'integer', 'user_level' => 'integer', 'msg_type' => 'integer', 'send_time' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select(['id', 'username', 'nickname', 'avatar', 'role_id']);
    }
}
